package com.rgs.gateway.web.common.design.sign.strategy;

import com.rgs.gateway.common.enums.SignTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;

/**
 * @author RenGaoshuai
 * @date 2024/7/1 16:45
 * @description
 */
@Slf4j
public class SimuGatewaySignStrategy implements GatewaySignStrategy {

    @Override
    public String getSign(String appKey, String appSecret, String timestamp, Map<String, Object> params) {
        if (StringUtils.isEmpty(timestamp) || StringUtils.isEmpty(appKey) || StringUtils.isEmpty(appSecret)) {
            return null;
        }
        String appIdEncode = Base64.getEncoder().encodeToString(appKey.getBytes(StandardCharsets.UTF_8));
        String stringBuilder = appIdEncode + "|" + appSecret + "|" + timestamp;
        return DigestUtils.md5DigestAsHex(stringBuilder.getBytes()).toUpperCase();
    }

    @Override
    public Integer getSignType() {
        return SignTypeEnum.SIMU.getCodeValue();
    }
}
